package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class RegDemo {
    public static void main(String[] args) throws Exception {
        Userinfo uif=InputUtil.getInputObject(new Userinfo(),"欢迎注册");
        System.out.println(uif);

        Connection con= DBUtil.getConnection();
        System.out.println("与数据库建立连接成功");
        Statement stm=con.createStatement();

        String sql="INSERT INTO userinfo(username,password,nickname,age) \n" +
                   "VALUES('"+uif.getUsername()+"','"+ uif.getPassword()+"','"+ uif.getNickname()+"','"+ uif.getAge()+"');";
        System.out.println(sql);
        int num=stm.executeUpdate(sql);
        if (num>0){
            System.out.println("数据存入成功");
        }
        con.close();
    }
}
